<?php
/**
 * $Id: contestants.php 8 2010-05-05 10:12:35Z webbochsant $
 *  @package	Joomla
 *  @author Daniel Eliasson
* 	@copyright	Copyright (C) 2010 Stilero. All rights reserved.
* 	@license	GNU/GPL, see LICENSE.php
* 	Joomla! is free software. This version may have been modified pursuant
* 	to the GNU General Public License, and as distributed it includes or
* 	is derivative of works licensed under the GNU General Public License or
* 	other free or open source software licenses.
*/

// no direct access
defined('_JEXEC') or die('Restricted access'); 

class VmcompetitionsControllerContestants extends VmcompetitionsController
{
/**
	 * constructor (registers additional tasks to methods)
	 * @return void
	 */
	function __construct()
	{
	    parent::__construct();
	 
	    // Register Extra tasks
	    $this->registerTask( 'add'  ,     'edit' );
	}
	
	function display()
    {
    	$modelContestants =& $this->getModel('Contestants');
    	JRequest::setVar( 'view', 'contestants' );
        parent::display();
    }
	/**
	 * display the edit form
	 * @return void
	 */
	function edit()
	{
	    JRequest::setVar( 'view', 'contestant' );
	    JRequest::setVar( 'layout', 'form'  );
	    //Hide the menu when we are editing
	    JRequest::setVar('hidemainmenu', 1);
	    	    
	    parent::display();
	}
	
	/**
	 * save a record (and redirect to main page)
	 * @return void
	 */
	function save()
	{
	    $model = $this->getModel('vmcompetition');
	    
	 
	    if ($model->store()) {
	        $msg = JText::_( 'Contestant Saved!' );
	    } else {
	        $msg = JText::_( 'Error Saving Contestant' );
	    }
	 
	    // Check the table in so it can be edited.... we are done with it anyway
	    $link = 'index.php?option=com_vmcompetition&controller=contestants';
	    $this->setRedirect($link, $msg);
	}
	
	/**
	 * remove record(s)
	 * @return void
	 */
	function remove()
	{
	    $model = $this->getModel('contestant');
	    if(!$model->delete()) {
	        $msg = JText::_( 'Error: One or More Contestants Could not be Deleted' );
	    } else {
	        $msg = JText::_( 'Contestant(s) Deleted' );
	    }
	 
	    $this->setRedirect( 'index.php?option=com_vmcompetition&controller=contestants', $msg );
	}
	/**
	 * cancel editing a record
	 * @return void
	 */
	function cancel()
	{
	    $msg = JText::_( 'Operation Cancelled' );
	    $this->setRedirect( 'index.php?option=com_vmcompetition&controller=contestants', $msg );
	}
	
	function publish()
	{
		global $option;
		
		$cid = JRequest::getVar( 'cid', array(), '', 'array' );
		
		if( $this->_task == 'publish')
		{
			$publish = 1;
		}
		else
		{
			$publish = 0;
		}
		
		$table =& JTable::getInstance('contestant', 'Table');
		$table->publish($cid, $publish);
		$this->setRedirect( 'index.php?option=' . $option);
	}
	
}

?>